package net.sxnic.workflow.transition;

import net.sxinfo.core.spring25.Dao;
import net.sxinfo.core.spring25.DefaultManager;
import net.sxnic.workflow.node.Node;
import net.sxnic.workflow.node.NodeManager;
import net.sxnic.workflow.pd.Pd;
import net.sxnic.workflow.transition.dao.TransitionDao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("trsManger")
public class DefaultTransitionManager extends
		DefaultManager<Transition, TransitionDao, String> implements
		TransitionManager {

	@Autowired
	private TransitionDao trsDao;
	
	@Autowired
	private NodeManager nodeManager;

	@Override
	protected Dao<Transition, String> getEntityDao() {
		return trsDao;
	}

	@Override
	public Transition save(String trsName, String fromNodeName, String toNodeName,
			Pd pd) {
		
		Node fromNode = nodeManager.findByPdName(pd, fromNodeName);
		Node toNode = nodeManager.findByPdName(pd, toNodeName);
		
		Transition trs = new Transition(trsName);
		trs.setFrom(fromNode);
		trs.setTo(toNode);
		trs.setPd(pd);
		
		trsDao.save(trs);
		
		return trs;
	}


}
